<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/include/taglibs.jsp" %>
<html>
<head>
    <%@include file="/include/header.html" %>
    <script type="text/javascript" src="${ctx}/appjs/elec/securityPrevention.js"></script>
    <link rel="stylesheet" href="${ctx}/libjs/plugins/moreSelect/moreSelect.css">
    <script src="${ctx}/libjs/plugins/moreSelect/moreSelect.js"></script>
    <style>
        .delList{
            color: #fff !important;
        }
    </style>
</head>

<script type="text/javascript">
    $('#topLink', window.parent.document).html(function (i, origText) {
        return '<ol class="breadcrumb">' +
            '<li class="breadcrumb-item">' +
            '<a href="">主页</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<a>设备管理</a>' +
            '</li>' +
            '<li class="breadcrumb-item">' +
            '<strong>安全防护</strong>' +
            '</li>' +
            '</ol>';
    });

</script>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <div class="columns pull-left">
                        <h5 class="font-bold">安全防护</h5>
                    </div>
                    <div class="ibox-tools">
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <form class="form-horizontal m-t layui-form" id="frmSecurityPrevention">
                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">充电中车辆电池温度限制：</label>
                            <div class="col-sm-1">

                                <input type="radio" class="form-control" name="openChargeLimitBatteryTemp" lay-filter="openChargeLimitBatteryTemp"
                                       title="开启" value="0"
                                       <c:if test="${tenantSetting.openChargeLimitBatteryTemp == '0'}">checked</c:if> >
                            </div>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control" name="openChargeLimitBatteryTemp"
                                       lay-filter="openChargeLimitBatteryTemp" title="关闭" value="1" lay-filter="openChargeLimitBatteryTemp"
                                       <c:if test="${tenantSetting.openChargeLimitBatteryTemp == '1'}">checked</c:if>     >
                            </div>
                            <span style="display: inline;color: #888888">*充电中电池正常温度小于50°C,50~60°C为危险温度,达到限制温度后将自动停止充电,请合理设置</span>
                        </div>

                        <div class="form-group row batteryWrap">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-9">
                                <div class="layui-card ">
                                    <c:forEach  begin="0" end="4" var="i">
                                        <div class="layui-card-body coupon-layui-card-body-battery coupon-layui-card-body-battery${i+1} hide col-sm-10 row">

                                        <div class=" layui-form-mid layui-word-aux">最高充电温度</div>
                                        <div class="col-sm-2" style="margin-right:70px;">
                                            <input class="form-control limitBatteryTemp" type="number"
                                                   onkeyup="num(this)" oninput="if(value<=0)value=''">
                                        </div>
                                        <div class=" layui-form-mid layui-word-aux">适用范围</div>
                                        <div class="col-sm-4">
                                            <div class=" selectPickerWrapper${i+1} wrapper batterySelect" <%--data-checks="1,2,3"--%> data-model="温度站点" >
                                                <%--<select class="hidden"></select>--%>
                                            </div>
                                        </div>
                                        <a class="btn btn-danger <c:if test="${i==0}">hide</c:if> btn-sm del_btn delList">删除</a>
                                    </div>
                                    </c:forEach>
                                </div>
                                <a class="btn btn-primary btn-sm addBatteryList" onclick="addBatteryList(this)"
                                   style="margin-top: 3px;color: #fff">增加限制范围</a>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 col-form-label text-right">车辆充电SOC限制：</label>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control" name="openChargeLimitSoc" lay-filter="openChargeLimitSoc"
                                       title="开启" value="0"
                                       <c:if test="${tenantSetting.openChargeLimitSoc == '0'}">checked</c:if> >
                            </div>
                            <div class="col-sm-1">
                                <input type="radio" class="form-control" name="openChargeLimitSoc"
                                       lay-filter="openChargeLimitSoc" title="关闭" value="1" lay-filter="openChargeLimitSoc"
                                       <c:if test="${tenantSetting.openChargeLimitSoc == '1'}">checked</c:if>     >
                            </div>
                            <span style="display: inline;color: #888888">*过量充电会损害电池,达到限制SOC后将自动停止充电,请合理设置</span>
                        </div>


                        <div class="form-group row socWrap">
                            <label class="col-sm-3 col-form-label text-right"></label>
                            <div class="col-sm-9">
                                <div class="layui-card">
                                    <c:forEach  begin="0" end="4" var="i">
                                    <div class="layui-card-body coupon-layui-card-body-SOC coupon-layui-card-body-SOC${i+1} hide col-sm-10 row">
                                        <div class=" layui-form-mid layui-word-aux">最高充电SOC</div>
                                        <div class="col-sm-2" style="margin-right:70px; ">
                                            <input class="form-control limitSOCTemp" oninput="if(value<=0)value='';if(value>100)value='100'" type="number" onkeyup="num(this)">
                                        </div>
                                        <div class=" layui-form-mid layui-word-aux">适用范围</div>
                                        <div class="col-sm-4">
                                            <%--<select class="form-control stationId" id="SOCId">--%>
                                            <%--</select>--%>
                                            <div class=" selectPickerWrapper${i+1} socSelect" <%--data-checks="1,2,3"--%> data-model="SOC站点" >
                                                <%--<select class="hidden"></select>--%>
                                            </div>
                                        </div>
                                        <a class="btn btn-danger <c:if test="${i==0}">hide</c:if> btn-sm del_btn delSOCList" style="color: #fff">删除</a>
                                        <%--<a class="btn btn-danger  btn-sm del_btn delList">删除</a>--%>
                                    </div>
                                    </c:forEach>
                                </div>
                                <a class="btn btn-primary btn-sm addSOCList" onclick="addSOCList(this)"
                                   style="margin-top: 3px;color: #fff">增加限制范围</a>
                            </div>
                        </div>

                        <div class="couponHtml hide"></div>
                        <div class="form-group">
                            <%--<div class="col-sm-3 col-sm-offset-8 text-right">--%>
                                <button type="submit" style="margin: 20px  auto 0"  class="btn btn-primary">提交</button>
                            <%--</div>--%>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var orginMap = [];
    var map = [];
    var index = 0
    layui.use(['form', 'jquery', 'tree', 'laydate', 'util'], function () {
        var form = layui.form;
        var $ = layui.jquery;

        form.on("radio(openChargeLimitBatteryTemp)", function (data) {
            if ($(this).val() == "0") {
                $(".batteryWrap").removeClass("hide");
            } else {
                $(".batteryWrap").addClass("hide");
            }
        });
        form.on("radio(openChargeLimitSoc)", function (data) {
            if ($(this).val() == "0") {
                $(".socWrap").removeClass("hide");
            } else {
                $(".socWrap").addClass("hide");
            }
        });
    })

    $(function () {
        $(".ibox-content").css("height", $(window).height() - 80);
        $.ajax({
            "type": "GET",
            "url": prefix + "/listElecStationData",
            "data": {},
            "success": function (data) {
                var str = '';
                for (var i = 0; i < data.length; i++) {
                    var stationObj = {};
                    stationObj.text = data[i].stationName;
                    stationObj.val = data[i].elecStationId;
                    map.push(stationObj);
                    orginMap.push(stationObj);
                    // str += "<option value=" + data[i].elecStationId + ">" + data[i].stationName + "</option>"
                }
            },
            complete:function () {
                var batteryDataList = [];
                var socDataList = [];
                $.ajax({
                    "type": "GET",
                    "url": prefix + "/listSecurityPrevention",
                    "data": {},
                    "success": function (data) {
                        if(data.data.openChargeLimitBatteryTemp=="1"){
                            $(".batteryWrap").addClass("hide");
                        }
                        if(data.data.openChargeLimitSoc=="1"){
                            $(".socWrap").addClass("hide");
                        }
                        if(data.data.batteryList){
                            batteryDataList = JSON.parse(data.data.batteryList);
                        }else{
                            batteryDataList = [];
                        }
                        if(data.data.socList){
                            socDataList  = JSON.parse(data.data.socList);
                        }else{
                            socDataList  = [];
                        }
                        if(batteryDataList.length==0){
                            $(".coupon-layui-card-body-battery1").removeClass("hide");
                            $(".batterySelect").eq(0).data("init",JSON.stringify(map)).data("checks","");
                            $(".batterySelect").eq(0).mySelect({
                                showCancel:true,
                                showSearch:true,
                                multiple:true
                            });
                        }else{
                            for(var i=0;i<batteryDataList.length;i++){
                                $(".coupon-layui-card-body-battery"+(i+1)).removeClass("hide");
                                $(".limitBatteryTemp").eq(i).val(batteryDataList[i].temp)
                                $(".batterySelect").eq(i).data("init",JSON.stringify(map)).data("checks",batteryDataList[i].stationId);
                                $(".batterySelect").eq(i).mySelect({
                                    showCancel:true,
                                    showSearch:true,
                                    multiple:true
                                });
                            }
                        }

                        if(socDataList.length==0){
                            $(".coupon-layui-card-body-SOC1").removeClass("hide");
                            $(".socSelect").eq(0).data("init",JSON.stringify(map)).data("checks","");
                            $(".socSelect").eq(0).mySelect({
                                showCancel:true,
                                showSearch:true,
                                multiple:true
                            });
                        }else{
                            for(var i=0;i<socDataList.length;i++){
                                $(".coupon-layui-card-body-SOC"+(i+1)).removeClass("hide");
                                $(".limitSOCTemp").eq(i).val(socDataList[i].temp)
                                $(".socSelect").eq(i).data("init",JSON.stringify(map)).data("checks",socDataList[i].stationId);
                                $(".socSelect").eq(i).mySelect({
                                    showCancel:true,
                                    showSearch:true,
                                    multiple:true
                                });
                            }
                        }
                        if($(".coupon-layui-card-body-battery.hide").length<1){
                            $(".addBatteryList").addClass("hide");
                        }
                        if($(".coupon-layui-card-body-SOC.hide").length<1){
                            $(".addSOCList").addClass("hide");
                        }
                    },
                })




                // console.log(data)
                // $(".batterySelect").eq(0).data("init",JSON.stringify(map)).data("checks","");
                // $(".batterySelect").eq(0).mySelect({
                //     showCancel:true,
                //     showSearch:true,
                //     multiple:true
                // });
                // $(".batterySelect").eq(1).data("init",JSON.stringify(map)).data("checks","");
                // $(".batterySelect").eq(1).mySelect({
                //     showCancel:true,
                //     showSearch:true,
                //     multiple:true
                // });
                // $(".batterySelect").eq(2).data("init",JSON.stringify(map)).data("checks","");
                // $(".batterySelect").eq(2).mySelect({
                //     showCancel:true,
                //     showSearch:true,
                //     multiple:true
                // });
                // $(".socSelect").eq(0).data("init",JSON.stringify(map)).data("checks","107,108");;
                // $(".socSelect").eq(0).mySelect({
                //     showCancel:true,
                //     showSearch:true,
                //     multiple:true
                // });
                // $(".socSelect").eq(1).data("init",JSON.stringify(map)).data("checks","10001,10002");;
                // $(".socSelect").eq(1).mySelect({
                //     showCancel:true,
                //     showSearch:true,
                //     multiple:true
                // });
            }
        })
    })

    function addBatteryList() {
        var index = $(".coupon-layui-card-body-battery.hide").index();
        if(index>0 && !$(".coupon-layui-card-body-battery.hide").eq(0).attr("delList")){
            $(".batterySelect").eq(index).data("init",JSON.stringify(map)).data("checks","");
            $(".batterySelect").eq(index).mySelect({
                showCancel:true,
                showSearch:true,
                multiple:true
            });
        }else if(index<0 && !$(".coupon-layui-card-body-battery.hide").eq(0).attr("delList")){
            $(".batterySelect:last").data("init",JSON.stringify(map)).data("checks","");
            $(".batterySelect:last").mySelect({
                showCancel:true,
                showSearch:true,
                multiple:true
            });
        }
        $(".coupon-layui-card-body-battery.hide").eq(0).removeClass("hide");
        if($(".coupon-layui-card-body-battery.hide").length<1){
            $(".addBatteryList").addClass("hide");
        }
    }


    function addSOCList() {
        var index = $(".coupon-layui-card-body-SOC.hide").index();
        if(index>0 && !$(".coupon-layui-card-body-SOC.hide").eq(0).attr("delList")){
            $(".socSelect").eq(index).data("init",JSON.stringify(map)).data("checks","");
            $(".socSelect").eq(index).mySelect({
                showCancel:true,
                showSearch:true,
                multiple:true
            });
        }else if(index<0&& !$(".coupon-layui-card-body-SOC.hide").eq(0).attr("delList")){
            $(".socSelect:last").data("init",JSON.stringify(map)).data("checks","");
            $(".socSelect:last").mySelect({
                showCancel:true,
                showSearch:true,
                multiple:true
            });
        }
        $(".coupon-layui-card-body-SOC.hide").eq(0).removeClass("hide");
        if($(".coupon-layui-card-body-SOC.hide").length<1){
            $(".addSOCList").addClass("hide");
        }
    }

    addSecurityPrevention.init();
</script>
</body>
</html>
